﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using FrameWork.Components;
using FrameWork.WebControls;

namespace FrameWork.web.Module.IntegralMS.IntegralMS.StudentManager
{
    public partial class StudentManager : System.Web.UI.Page
    {
        public string U_PhotoUrl_Js = "";
        public string MaxImgUrl = "";
        int StuID = (int)Common.sink("StuID", MethodType.Get, 50, 0, DataType.Int);
        string CMD = (string)Common.sink("CMD", MethodType.Get, 50, 0, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            FrameWorkPermission.CheckPagePermission(CMD);//检查权限
            if (!Page.IsPostBack)
            {
                OnStart();//初始化
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        private void OnStart()
        {
            stu_StudentInfoTable st = BusinessFacade.sys_StudentInfoDisp(StuID);//获得学生对象
            OnStartData(st);
            if (CMD == "List")
            {
                // DispTr.Visible = true;
                HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
                bi1.ButtonPopedom = PopedomType.Edit;
                bi1.ButtonName = "学员";
                bi1.ButtonUrl = string.Format("?CMD=Edit&StuID={0}", StuID);
                HeadMenuWebControls1.ButtonList.Add(bi1);
                Hidden_Input();
                PostButton.Visible = false;
            }
            else if (CMD == "New")
            {
                DisplayInput();
            }
            else if (CMD == "Edit")
            {
                Hidden_Disp();
                HeadMenuButtonItem bi5 = new HeadMenuButtonItem();
                bi5.ButtonIcon = "back.gif";
                bi5.ButtonPopedom = PopedomType.List;
                bi5.ButtonName = "返回";
                bi5.ButtonUrl = string.Format("?CMD=List&StuID={0}", StuID);
                HeadMenuWebControls1.ButtonList.Add(bi5);
                HeadMenuButtonItem bi2 = new HeadMenuButtonItem();
                bi2.ButtonPopedom = PopedomType.Delete;
                bi2.ButtonName = "学员";
                bi2.ButtonUrlType = UrlType.JavaScript;
                bi2.ButtonUrl = string.Format("DelData('?CMD=Delete&StuID={0}')", StuID);
                HeadMenuWebControls1.ButtonList.Add(bi2);
            }
            else if (CMD == "Delete")
            {
                st.DB_Option_Action_ = "Delete";
                BusinessFacade.stu_StudentInsertUpdate(st);
            }

        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
            S_Name.Visible = false;
            S_ClassID.Visible = false;
            U_GroupID_Span.Visible = false;
            S_Sex.Visible = false;
            S_BirthDay.Visible = false;
            S_IDCard.Visible = false;
            S_HomeTel.Visible = false;
            S_MobileNo.Visible = false;
        }
        void DisplayInput()
        {
            S_Name.Visible = true;
        }
        /// <summary>
        /// 显示框
        /// </summary>
        private void Hidden_Disp()
        {
            S_Name.Visible = false;
            S_ClassID.Visible = false;
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(stu_StudentInfoTable st)
        {
            #region 显示数据
            S_Name.Value = st.S_Name;
            S_ClassID_Txt.Value = BusinessFacade.stu_ClassInfoDisp(st.S_ClassID).C_CName;//班级名
            S_ClassID.Value = st.S_ClassID.ToString();//班级编号
            S_Sex.SelectedValue = st.S_Gender == true ? "1" : "0";
            S_BirthDay.Value = st.S_Birth.ToShortDateString();
            S_IDCard.Text = st.S_CardID;
            S_MobileNo.Text = st.S_Phone;
            S_HomeTel.Text = st.S_HomePhone;
            S_StudyDate.Value = st.S_StudyDate.ToShortDateString();
            #endregion
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string S_Name_Txt = (string)Common.sink(S_Name.UniqueID, MethodType.Post, 20, 1, DataType.Str);//姓名
            int S_ClassID_Txt = (int)Common.sink(S_ClassID.UniqueID, MethodType.Post, 50, 1, DataType.Int); //班级
            bool S_Sex_Txt = (string)Common.sink(S_Sex.UniqueID, MethodType.Post, 10, 1, DataType.Str) == "1" ? true : false; ;//性别
            string S_IDCard_Txt = (string)Common.sink(S_IDCard.UniqueID, MethodType.Post, 20, 1, DataType.Str);//身份证
            string S_Home_Tel_Txt = (string)Common.sink(S_HomeTel.UniqueID, MethodType.Post, 20, 1, DataType.Str); //家中电话
            string S_MobileNo_Txt = (string)Common.sink(S_MobileNo.UniqueID, MethodType.Post, 20, 1, DataType.Str); //手机号
            DateTime S_BirthDay_Txt = (DateTime)Common.sink(S_BirthDay.UniqueID, MethodType.Post, 30, 1, DataType.Dat);//出生年月
            DateTime S_StudyDate_Txt = (DateTime)Common.sink(S_StudyDate.UniqueID, MethodType.Post, 30, 1, DataType.Dat);//入学日期
            PopedomType pt = PopedomType.New;
            string All_Title_Txt = "增加";
            stu_StudentInfoTable st = BusinessFacade.sys_StudentInfoDisp(StuID);
            if (CMD == "New")
            {
                st.DB_Option_Action_ = "Insert";
            }
            else if (CMD == "Edit")
            {
                pt = PopedomType.Edit;
                All_Title_Txt = "修改";
                st.DB_Option_Action_ = "Update";
            }
            else
            {
                EventMessage.MessageBox(2, "CMD值无效", "无效操作命令!", Icon_Type.Error, Common.GetHomeBaseUrl("Index.aspx"));
            }
            st.S_Name = S_Name_Txt;
            st.S_ClassID = S_ClassID_Txt;
            st.S_Gender = S_Sex_Txt;
            st.S_CardID = S_IDCard_Txt;
            st.S_HomePhone = S_Home_Tel_Txt;
            st.S_Phone = S_MobileNo_Txt;
            st.S_Birth = S_BirthDay_Txt;
            st.S_StudyDate = S_StudyDate_Txt;
            st.S_Photo = new byte[1];
            if (BusinessFacade.sys_StudentInfoTableCheckPK(st))
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("存在相同的值({0})!", st.StuID), Icon_Type.Alert, Common.GetHomeBaseUrl("Index.aspx"));
            }
            int rInt = BusinessFacade.stu_StudentInsertUpdate(st);
            EventMessage.MessageBox(1, "操作成功", string.Format("{1}ID({0})成功!", StuID, All_Title_Txt), Icon_Type.OK, Common.GetHomeBaseUrl("Index.aspx"));
        }
    }
}